

function SwakFlasher(flashee) {
	this.flashee = flashee;
	this.flashInterval = 700;
	this.flashId = null;
	this.flashCount = 0;
	this.flashNumber = 0;
	this.flashText = '';
	this.normalText = '';

	this.kwButtonStatusDisabled = "disabled"; //off
	this.kwButtonStatusOff = "off"; //off
	this.kwButtonStatusOn = "on"; //on	
	
	
	this.flash = function(numberOfFlashes){ 
		if (numberOfFlashes == null) numberOfFlashes = -1;
		if (this.flashId != null) {
			this.flashCount = 0;
			this.flashNumber = numberOfFlashes;
			//another event to flash, result counter
			//clearInterval(this.kwFlashId);
			//this.kwStatusPanel.setAttribute("status", handle.kwButtonStatusOff);
		}
		else {
	
			this.flashNumber = numberOfFlashes;
			//alert('flashKeywordButton entered ' + this.kwFlashId );
			this.flashCount = 0;
			this.flashId = setInterval(this.submitFlash, this.flashInterval, this);
			//alert('flashKeywordButton entered ' + this.kwFlashId );
			this.flashee.tooltipText=this.flashText;
		}		
	}
	
	this.submitFlash = function(handle) {
		if (handle == null) return;
		//alert('submitFlash ' + handle.flashee);
		if (handle.flashee == null) return;
		var kwbstatus = (handle.flashee.getAttribute("status") == handle.kwButtonStatusOn)? handle.kwButtonStatusOff: handle.kwButtonStatusOn;
		handle.flashee.setAttribute("status", kwbstatus);
		if (handle.flashNumber != -1) {
			
	
			if (handle.flashCount >= handle.flashNumber) {
				//alert(handle.flashCount + ' clear flash ' + numFlashes);
				clearInterval(handle.flashId);
				handle.flashId = null;
				handle.flashee.setAttribute("status", handle.kwButtonStatusOff);
				handle.flashee.tooltipText=handle.normalText;
				handle.flashCount = 0;
				handle.flashNumber = 0;
			}
			if (kwbstatus == handle.kwButtonStatusOn) handle.flashCount++;
		}		
	}
	
	this.dispose = function() {
		if (this.flashId != null) {
			clearInterval(this.flashId);
		}
		this.flashee = null;
		this.flashId = null;
		this.flashText = null;
		this.normalText = null;
	}
	
}


function StatusBarManager() {
	this.saleInfoState = 0;
	this.maxSaleInfoState = 2;
}

StatusBarManager.prototype.kwStatusPanel = null; 
StatusBarManager.prototype.kwButtonStatusDisabled = "disabled"; //off
StatusBarManager.prototype.kwButtonStatusOff = "off"; //off
StatusBarManager.prototype.kwButtonStatusOn = "on"; //on
StatusBarManager.prototype.kwInterval = 700; //half second
StatusBarManager.prototype.kwFlashId = null;
StatusBarManager.prototype.kwFlashCount = 0;
StatusBarManager.prototype.kwFlashNumber = 0;  //number of requested flashes
StatusBarManager.prototype.pmStatusPanel = null; 
StatusBarManager.prototype.lrStatusPanel = null; 
StatusBarManager.prototype.saleStatusPanel = null; 
StatusBarManager.prototype.saleIntervalId = null;
StatusBarManager.prototype.saleInterval = 5000;
StatusBarManager.prototype.defaultSaleInterval = 5000;
StatusBarManager.prototype.oldState = null;

StatusBarManager.prototype.kwFlashObject = null;
StatusBarManager.prototype.pmFlashObject = null;
//StatusBarManager.prototype.saleInfoState = 0;


StatusBarManager.prototype.retailPrice = null;
StatusBarManager.prototype.discountPercent = null;
StatusBarManager.prototype.salePrice = null;

StatusBarManager.prototype.resetPriceInfo = function(handle)
{
	if (handle == null) return;
	handle.retailPrice = null;
	handle.discountPercent = null;
	handle.salePrice = null;
}



StatusBarManager.prototype.flashKeywordButton = function(numberOfFlashes) {
	if (this.kwFlashObject == null) return;
	this.kwFlashObject.flash(numberOfFlashes);
	return;
	//alert('flashKeywordButton entered ' + this.kwFlashId );
	if (numberOfFlashes == null) numberOfFlashes = -1;
	
	if (this.kwFlashId != null) {
		this.kwFlashCount = 0;
		this.kwFlashNumber = numberOfFlashes;
		//another event to flash, result counter
		//clearInterval(this.kwFlashId);
		//this.kwStatusPanel.setAttribute("status", handle.kwButtonStatusOff);
	}
	else {

		this.kwFlashNumber = numberOfFlashes;
		//alert('flashKeywordButton entered ' + this.kwFlashId );
		this.kwFlashCount = 0;
		this.kwFlashId = setInterval(this.submitFlashKeyword, this.kwInterval, this);
		//alert('flashKeywordButton entered ' + this.kwFlashId );
		this.kwStatusPanel.tooltipText='Look Who\'s Talking';
	}
}

StatusBarManager.prototype.submitFlashKeyword = function(handle) {
	if (handle == null) return;
	if (handle.kwStatusPanel == null) return;
	var kwbstatus = (handle.kwStatusPanel.getAttribute("status") == handle.kwButtonStatusOn)? handle.kwButtonStatusOff: handle.kwButtonStatusOn;
	handle.kwStatusPanel.setAttribute("status", kwbstatus);
	if (handle.kwFlashNumber != -1) {
		

		if (handle.kwFlashCount >= handle.kwFlashNumber) {
			//alert(handle.kwFlashCount + ' clear flash ' + numFlashes);
			clearInterval(handle.kwFlashId);
			handle.kwFlashId = null;
			handle.kwStatusPanel.setAttribute("status", handle.kwButtonStatusOff);
			handle.kwStatusPanel.tooltipText='Chat Connected';
			handle.kwFlashCount = 0;
			handle.kwFlashNumber = 0;
		}
		if (kwbstatus == handle.kwButtonStatusOn) handle.kwFlashCount++;
	}
			
}

StatusBarManager.prototype.flashPMButton = function(numberOfFlashes) {
	if (this.pmFlashObject == null) return;
	if (this.isPMButtonFlashing() == true) {
		 return;
	}
	//alert('flash PM');
	this.pmFlashObject.flash(numberOfFlashes);
}

StatusBarManager.prototype.setKWStatusBarPanel = function(statusBarPanel)
{
 this.kwStatusPanel = statusBarPanel;
 this.kwFlashObject = new SwakFlasher(statusBarPanel);
 this.kwFlashObject.flashText = 'Look Who\'s Talking';
 this.kwFlashObject.normalText = 'Chat Connected';
 //if (this.kwStatusPanel == null) return;
 //this.kwStatusPanel.setAttribute("status", this.kwButtonStatusOff);
}

StatusBarManager.prototype.setKWStatusConnected = function()
{
 	if (this.kwStatusPanel == null) return;
 	if (this.kwFlashObject == null) {
 		this.kwFlashObject = new SwakFlasher(this.kwStatusPanel);
	}
 	this.kwStatusPanel.setAttribute("status", this.kwButtonStatusOff);
 	this.kwStatusPanel.tooltipText='Chat Connected';
}

StatusBarManager.prototype.setKWStatusDisabled = function()
{
 	if (this.kwStatusPanel == null) return;
 	if (this.kwFlashObject != null && this.kwFlashObject.flashId != null) {
 		clearInterval(this.kwFlashObject.flashId);
 		this.kwFlashObject.flashId = null;
 	}
 	this.kwStatusPanel.setAttribute("status", this.kwButtonStatusDisabled);
 // this.kwFlashId = null;
 // this.kwFlashCount = 0;
//	this.kwFlashNumber = 0;
//	this.kwStatusPanel.setAttribute("status", this.kwButtonStatusDisabled);
	this.kwStatusPanel.tooltipText='Chat Disconnected';
}

StatusBarManager.prototype.isKeywordButtonFlashing = function() {
	if (this.kwFlashObject == null) return false;
	var flash = this.kwFlashObject.flashId  == null ? false : true;
	return flash;
}

StatusBarManager.prototype.isPMButtonFlashing = function() {
	if (this.pmFlashObject == null) return false;
	var flash = this.pmFlashObject.flashId  == null ? false : true;
	return flash;
}

StatusBarManager.prototype.setPMStatusBarPanel = function(statusBarPanel)
{
 this.pmStatusPanel = statusBarPanel;
 if (this.pmStatusPanel == null) return;
 this.pmFlashObject = new SwakFlasher(this.pmStatusPanel);
 this.pmFlashObject.flashText = 'Special delivery awaits for you';
 this.pmFlashObject.normalText = 'Special delivery awaits for you';
 //this.pmStatusPanel.setAttribute("status", "on");
}

StatusBarManager.prototype.setPMStatusOn = function()
{
 if (this.pmStatusPanel == null) return;
 this.pmStatusPanel.setAttribute("status", this.kwButtonStatusOn);
 this.pmStatusPanel.tooltipText='Special delivery awaits for you';
}

StatusBarManager.prototype.setPMStatusOff = function()
{
 if (this.pmStatusPanel == null) return;
 if (this.isPMButtonFlashing() == true) {
 	clearInterval(this.pmFlashObject.flashId);
 	this.pmFlashObject.flashId = null;
 }
 this.pmStatusPanel.setAttribute("status", this.kwButtonStatusOff);
 this.pmStatusPanel.tooltipText='No messages';
}

StatusBarManager.prototype.setLRStatusBarPanel = function(statusBarPanel)
{
 this.lrStatusPanel = statusBarPanel;
 if (this.lrStatusPanel == null) return;
 //this.lrStatusPanel.setAttribute("status", "on");
}

StatusBarManager.prototype.setLRStatusOn = function()
{
 if (this.lrStatusPanel == null) return;
 this.lrStatusPanel.setAttribute("status", this.kwButtonStatusOn);
 this.lrStatusPanel.tooltipText='Someone is making a mess in your living room';
}

StatusBarManager.prototype.setLRStatusOff = function()
{
 if (this.lrStatusPanel == null) return;
 this.lrStatusPanel.setAttribute("status", this.kwButtonStatusOff);
  this.lrStatusPanel.tooltipText='Living room? More like \"Boring Room\" if you ask me';
}

StatusBarManager.prototype.hidePM = function(hidden) {
	if (this.pmStatusPanel)
		this.pmStatusPanel.setAttribute("hidden", hidden);
}

StatusBarManager.prototype.hideLR = function(hidden) {
	if (this.lrStatusPanel)
		this.lrStatusPanel.setAttribute("hidden", hidden);
}

StatusBarManager.prototype.hideKW = function(hidden) {
	if (this.kwStatusPanel)
		this.kwStatusPanel.setAttribute("hidden", hidden);
}

StatusBarManager.prototype.hideSale = function(hidden) {
	if (this.saleStatusPanel)
		this.saleStatusPanel.setAttribute("hidden", hidden);
}

StatusBarManager.prototype.hideStatusBar = function(hidden) {
	if (this.lrStatusPanel)
		this.lrStatusPanel.setAttribute("hidden", hidden);
	if (this.pmStatusPanel)
		this.pmStatusPanel.setAttribute("hidden", hidden);
	if (this.kwStatusPanel)
		this.kwStatusPanel.setAttribute("hidden", hidden);
	if (this.saleStatusPanel)
		this.saleStatusPanel.setAttribute("hidden", hidden);					
}

StatusBarManager.prototype.setSaleStatusBarPanel = function(statusBarPanel)
{
 this.saleStatusPanel = statusBarPanel;
}

StatusBarManager.prototype.setSaleStatusDisconnected = function()
{
	//alert('call to setSaleStatusDisconnected');
 if (this.saleStatusPanel == null) return;
 this.saleStatusPanel.label="JellyFish";
 this.saleStatusPanel.tooltipText="Not Connected";
}

StatusBarManager.prototype.toggleSaleInfo = function() {
	if (this.saleInfoState == null || this.saleInfoState == 'undefined') this.saleInfoState = 0;
	this.saleInfoState++;
	this.saleInfoState = this.saleInfoState % 3;
	//alert('sbm change ' + this.saleInfoState);
	this.monitorState(this.defaultSaleInterval);
}

StatusBarManager.prototype.isMonitoring = function() {
	if (this.saleIntervalId != null) {
		return true;
	}
	return false;
}

StatusBarManager.prototype.monitorState = function(interval)
{
	if (this.saleInfoState == null || this.saleInfoState == 'undefined') this.saleInfoState = 0;
	//alert('sb start monitor ' + interval);
	//alert('monitorState ' + this.saleStatusPanel);
	if (this.saleStatusPanel == null) return;
	if (this.saleIntervalId != null) {
		//this.stopMonitorState();
		//alert('calling refreshSaleStatus');
		this.refreshSaleStatus(this);
		//alert('done calling refreshSaleStatus');
	}
	else {
		this.saleInterval = interval;
		this.saleIntervalId = setInterval(this.refreshSaleStatus, this.saleInterval, this);
	}
	//this.refreshSaleStatus(this);
}

StatusBarManager.prototype.refreshState = function()
{
	this.refreshSaleStatus(this);
}

StatusBarManager.prototype.stopMonitorState = function()
{
	//alert('sb stop monitor');
	if (this.saleIntervalId != null) {
		clearInterval(this.saleIntervalId);
		this.saleIntervalId = null;
	}
	this.saleStatusPanel.label='JellyFish';
	this.saleStatusPanel.tooltipText='Not monitoring';
	//this.refreshSaleStatus(this);
}

StatusBarManager.prototype.refreshSaleStatus = function(handle)
{
	//alert('SBM refreshSaleStatus');
	if (handle.saleStatusPanel == null && handle.saleIntervalId != null) {
		clearInterval(handle.saleIntervalId);
		return;
	}
	
	var state = SMACK_STATE_UNKNOWN;
	if (swaksmack.smackShopContentWindow != null) {
		state = swaksmack.SS_JF.getState();
	}
	
	//handle state change
	if (handle.oldState != state) {
		resetBuyPrice();
	}
	//alert('pre get state ' + swaksmack.SS_JF);
	//var state = swaksmack.alertManager.state;
	
	//alert(this.saleInfoState + ' state ' + state);
	
	processMyBuyPrice(handle, state);
	
	var titleEnabled = SS_getPreference(SMACK_DISPLAYTITLEINFO);
	
	if (state == SMACK_STATE_NONGURUDEAL || state == SMACK_STATE_GURUGUESSMADE || state == SMACK_STATE_GURUGUESSMISSED || state == SMACK_STATE_SMACKPOT_BETCLOSED) {
		try {
			handle.resetPriceInfo(handle);
			var salelabel = 'Deal';
			var saleTT = 'Deal';
			var retail = swaksmack.SmackShopDoc.getElementById('retailPrice');
			var item = swaksmack.SmackShopDoc.getElementById('productNameAnchor');
			
			
			switch(handle.saleInfoState) {
				case 0:
					var cost = swaksmack.SmackShopDoc.getElementById('totalCost');
					salelabel = cost.textContent;
					saleTT = item.textContent + '   Retail: ' + retail.textContent;		
					break;
				case 1:
					var cost = swaksmack.SmackShopDoc.getElementById('slider');
					salelabel = cost.textContent;	
					saleTT = item.textContent + '   Retail: ' + retail.textContent;		
					break;
				case 2:
					var coinswon = swaksmack.coinsWonDuringShow;	
					salelabel = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
					saleTT = 'Coins won in last deal/Coins won during show/Coins won this session';
					break;		
				default: 
					handle.saleInfoState = 0;
				
			}


      if (bAletSent == true || MyBuyPrice==null || MyBuyPrice == 0) {
			    handle.saleStatusPanel.label=salelabel;
			    handle.saleStatusPanel.tooltipText=saleTT;
		  }
		}
		catch (x) {
			handle.saleStatusPanel.label="Product Error";
			handle.saleStatusPanel.tooltipText=x;
		}
		
		if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
	  }
		
	}

	else if (state == SMACK_STATE_NONGURUDEALSOLD) {
		var sbtext = 'Sold';
	 
	  /*
	  try {
	  	var coins = swaksmack.SS_JF.getSmackPotCoinsWon();
	  	handle.saleStatusPanel.tooltipText='Coins Won: ' + coins;
	  }
	  catch(x){
	  	handle.saleStatusPanel.tooltipText='Item sold';
	  }
	  */
	  
	  if (handle.salePrice == null) {
		  try {
		  	handle.retailPrice = swaksmack.SS_JF.getRetailPrice();
		  	handle.discountPercent = swaksmack.SS_JF.getDiscount();
		  	handle.salePrice = swaksmack.SS_JF.getSalePrice(handle.retailPrice,handle.discountPercent);
		  	if (handle.salePrice != null) {
		  		sbtext='Sold $' + handle.salePrice;
		  		handle.saleStatusPanel.tooltipText='Item sold for $' + handle.salePrice;
		  	}
		  }
		  catch (x) {
		  	handle.saleStatusPanel.tooltipText='Item sold';
		  }
		}
		else {
			sbtext='Sold $' + handle.salePrice;
			handle.saleStatusPanel.tooltipText='Item sold for $' + handle.salePrice;
		}
		 handle.saleStatusPanel.label=sbtext;
	  
	  //note--i've repeated this in each state eval where appropriate as I try to figure out what other info
	  //to stash in there...once this has run its cource, refactor where possible
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;	
				break;
	  }
	  
	  	if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
		
	}
	else if (state == SMACK_STATE_SMACKPOT_BETOPEN) {
		handle.saleStatusPanel.label="SmackPot Bet ";
		handle.saleStatusPanel.tooltipText='Place your bets';
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;	
				break;
	  }
	  
  	if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}		
	}
	else if (state == SMACK_STATE_SMACKPOT_BETMADE) {
		handle.saleStatusPanel.label="Bets Placed";
		handle.saleStatusPanel.tooltipText='Mamma needs a new pair of shoes';
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	  		
	}		
	else if (state == SMACK_STATE_OUTWITVOTE) {
		handle.saleStatusPanel.label="Outwit Vote";
		handle.saleStatusPanel.tooltipText='Vote early, vote often';
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }
	  
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}		
	}	
	else if (state == SMACK_STATE_OUTWITOPTIN) {
		handle.saleStatusPanel.label="Opt In";
		
		var tttext = 'What are you waiting for?';
		if (handle.salePrice == null) {
		  try {
		  	handle.retailPrice = swaksmack.SS_JF.getRetailPrice();
		  	handle.discountPercent = swaksmack.SS_JF.getDiscount();
		  	handle.salePrice = swaksmack.SS_JF.getSalePrice(handle.retailPrice,handle.discountPercent);
		  	if (handle.salePrice != null) {
		  		tttext='Last item sold for $' + handle.salePrice;
		  	}
		  }
		  catch (x) {
		  	tttext='What are you waiting for?';
		  }
		}
		else {
			tttext='Last item sold for $' + handle.salePrice;
		}
		
		
		handle.saleStatusPanel.tooltipText=tttext;
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }	
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	  	
	}
	else if (state == SMACK_STATE_OUTWIT_VOTED) {
		handle.saleStatusPanel.label="Voted";
		handle.saleStatusPanel.tooltipText='I would have picked something else';
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	  		
	}
	else if (state == SMACK_STATE_OUTWITOPTINENTERED) {
		handle.saleStatusPanel.label='You\'re in';
		
		var tttext = 'Feelin Lucky?';
		if (handle.salePrice == null) {
		  try {
		  	handle.retailPrice = swaksmack.SS_JF.getRetailPrice();
		  	handle.discountPercent = swaksmack.SS_JF.getDiscount();
		  	handle.salePrice = swaksmack.SS_JF.getSalePrice(handle.retailPrice,handle.discountPercent);
		  	if (handle.salePrice != null) {
		  		tttext='Last item sold for $' + handle.salePrice;
		  	}
		  }
		  catch (x) {
		  	tttext='Feelin Lucky?';
		  }
		}
		else {
			tttext='Last item sold for $' + handle.salePrice;
		}
		
		handle.saleStatusPanel.tooltipText=tttext;
		
			
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;	
				break;
	  }	
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	  	
	}
	else if (state == SMACK_STATE_OUTWITCONTESTANTSELECTED) {
		handle.saleStatusPanel.label='Player Selected';
		handle.saleStatusPanel.tooltipText='If it wasn\'t me, I hope it was you';
		try {
			var pnid = swaksmack.SmackShopDoc.getElementById('playerName');
			if (pnid != null) {
				var nickname = swaksmack.SS_JF.getNickName();
				handle.saleStatusPanel.tooltipText=pnid.textContent;
				if (nickname == pnid.textContent) {
					handle.saleStatusPanel.label='You Are Selected';
				}
			}
		}
		catch (x){}
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }	
	  
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}	
	}
	else if (state == SMACK_STATE_OUTWITMISSED) {
		handle.saleStatusPanel.label = 'Missed';
		
		var tttext = 'You gotta be in it to win it';
		if (handle.salePrice == null) {
		  try {
		  	handle.retailPrice = swaksmack.SS_JF.getRetailPrice();
		  	handle.discountPercent = swaksmack.SS_JF.getDiscount();
		  	handle.salePrice = swaksmack.SS_JF.getSalePrice(handle.retailPrice,handle.discountPercent);
		  	if (handle.salePrice != null) {
		  		tttext='Last item sold for $' + handle.salePrice;
		  	}
		  }
		  catch (x) {
		  	tttext='You gotta be in it to win it';
		  }
		}
		else {
			tttext='Last item sold for $' + handle.salePrice;
		}			
		handle.saleStatusPanel.tooltipText=tttext;
		if (titleEnabled) {
			window.title = 'JellyFish: Outwit Missed';
		}		
	}
	else if (state == SMACK_STATE_OUTWITRESULT) {
		handle.saleStatusPanel.label="Outwit Result";
		
		
		
		handle.saleStatusPanel.tooltipText='I will get the answer next time';
		var winner = swaksmack.SS_JF.isGuruWinner();
		if (winner) {
			handle.saleStatusPanel.label="Outwit Point";
			handle.saleStatusPanel.tooltipText='Nice guess';
		}
		else {
			var other = swaksmack.SS_JF.isContestWinner();
			if (other) {
				handle.saleStatusPanel.label="Outwit Result";
				handle.saleStatusPanel.tooltipText='At least someone got a point';
			}
		}
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }		
	  
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	}	
	else if (state == SMACK_STATE_OUTWITSELECTCONTESTANT) {
		handle.saleStatusPanel.label="Player Selection";
		
		var tttext = 'Pick me, Pick me';
		if (handle.salePrice == null) {
		  try {
		  	handle.retailPrice = swaksmack.SS_JF.getRetailPrice();
		  	handle.discountPercent = swaksmack.SS_JF.getDiscount();
		  	handle.salePrice = swaksmack.SS_JF.getSalePrice(handle.retailPrice,handle.discountPercent);
		  	if (handle.salePrice != null) {
		  		tttext='Last item sold for $' + handle.salePrice;
		  	}
		  }
		  catch (x) {
		  	tttext='Pick me, Pick me';
		  }
		}
		else {
			tttext='Last item sold for $' + handle.salePrice;
		}
		
		handle.saleStatusPanel.tooltipText=tttext;
		
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';	
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }	
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	  	
	}
	else if (state == SMACK_STATE_GURUGUESSENTER) {
		handle.saleStatusPanel.label="Guru Guess";
		handle.saleStatusPanel.tooltipText='Enter your Guru Guess';
		
		if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	}
	else if (state == SMACK_STATE_GURUGUESSSOLD || state == SMACK_STATE_SMACKPOT_RESULTS) {
		var sbtext="Sold";
		/*
		if (state == SMACK_STATE_SMACKPOT_RESULTS) {
			handle.saleStatusPanel.tooltipText='Coins won: ' + swaksmack.SS_JF.getSmackPotCoinsWon();
		}
		else {
			handle.saleStatusPanel.tooltipText='Item sold';
		}
		*/
		var tttext = '';
		if (handle.salePrice == null) {
		  try {
		  	handle.retailPrice = swaksmack.SS_JF.getRetailPrice();
		  	handle.discountPercent = swaksmack.SS_JF.getDiscount();
		  	handle.salePrice = swaksmack.SS_JF.getSalePrice(handle.retailPrice,handle.discountPercent);
		  	if (handle.salePrice != null) {
		  	  sbtext='Sold $' + handle.salePrice;
		  		tttext='Item sold for $' + handle.salePrice;
		  	}
		  }
		  catch (x) {
		  	tttext='Item sold';
		  }
		}
		else {
			sbtext='Sold $' + handle.salePrice;
			tttext='Item sold for $' + handle.salePrice;
		}
		
		if (state == SMACK_STATE_SMACKPOT_RESULTS) {
			tttext=tttext + ', Coins won: ' + swaksmack.SS_JF.getSmackPotCoinsWon();
		}
		handle.saleStatusPanel.label=sbtext;
		handle.saleStatusPanel.tooltipText = tttext;
		
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }	
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}	
	}
	else if (state == SMACK_STATE_GURUGUESSWHEELSPIN) {
		handle.saleStatusPanel.label="Wheel Spin";
		handle.saleStatusPanel.tooltipText='The wheel on the smack goes round and round';
		if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	}
  else if (state == SMACK_STATE_GURUGUESSWHEELSPINSTOPPED) {
		handle.saleStatusPanel.label="Wheel Stopped";
		handle.saleStatusPanel.tooltipText='Wheel stopped';
		if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}
	}
	else if (state == SMACK_STATE_PREVIEW) {
		handle.saleStatusPanel.label="Preview";
		handle.saleStatusPanel.tooltipText='Waiting until next show...go do something';
		try {
			var lot = swaksmack.SmackShopDoc.getElementById('liveObjectTimer');
			handle.saleStatusPanel.label=lot.textContent;
		}
		catch (x){}
	  switch(handle.saleInfoState) {
	  	case 1:
			case 2:
				var coinswon = swaksmack.coinsWonDuringShow;	
				handle.saleStatusPanel.label = 'Coins won: ' + swaksmack.coinsWonOnLastItem + '/'+ coinswon +'/'+swaksmack.coinsWonDuringSession;
				handle.saleStatusPanel.tooltipText = 'Coins won in last deal/Coins won during show/Coins won this session';
				handle.saleInfoState = handle.maxSaleInfoState;
				break;
	  }	
	  if (titleEnabled) {
			window.title = 'JellyFish: ' + handle.saleStatusPanel.label;
		}	
	}
	else if (state == SMACK_STATE_UNKNOWN) {
		//alert(state + " unknown " + swaksmack.SS_JF.getTypeIdentifier() + " " + swaksmack.SS_JF.getGuruGuessState());
		handle.saleStatusPanel.label="Waiting...";
		handle.saleStatusPanel.tooltipText='Waiting for JellyFish.com data.  State info: ' + state + ' ' + swaksmack.SS_JF.getTypeIdentifier() + ' ' + swaksmack.SS_JF.getGuruGuessState();
	} 
	else {
		//alert(state + " " + swaksmack.SS_JF.getTypeIdentifier() + " " + swaksmack.SS_JF.getGuruGuessState());
		handle.saleStatusPanel.label='Where am I? '+ state;
		handle.saleStatusPanel.tooltipText='Look, he goofed, PM Mindstorm and tell him of the problem: ' + state + ' ' + swaksmack.SS_JF.getTypeIdentifier() + ' ' + swaksmack.SS_JF.getGuruGuessState();
	}
	handle.oldState = state;
	//handle.saleIntervalId = setInterval(this.refreshSaleStatus, this.saleInterval, this);
	
}



